home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / master / Examples / SimpleWin / simplewin.c next >
C/C++ Source or Header  |  1994-02-01  |  2KB  |  119 lines

  1.  
  2. /*
  3.  *  X.C
  4.  *
  5.  *  If you do not have the 2.0 includes you will need to remove the
  6.  *  #include <clib/#?> stuff and change IDCMP_* and WFLG_* to the
  7.  *  1.3 names (refer intuition/intuition.h)
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/screens.h>
  14. #include <clib/exec_protos.h>
  15. #include <clib/graphics_protos.h>
  16. #include <clib/intuition_protos.h>
  17.  
  18. typedef struct Screen Screen;
  19. typedef struct Window Window;
  20. typedef struct IntuiMessage IntuiMessage;
  21.  
  22. Screen *Scr;
  23. Window *Win;
  24.  
  25. struct NewScreen Ns = {
  26.     0, 0, 640, -1, 4,
  27.     -1, -1,
  28.     LACE|HIRES,
  29.     CUSTOMSCREEN,
  30.     NULL,
  31.     "Pixel Twiddle"
  32. };
  33.  
  34. struct NewWindow Nw = {
  35.     0, 0, 0, 0,
  36.     -1, -1,
  37.  
  38.     IDCMP_MOUSEBUTTONS|IDCMP_MOUSEMOVE|IDCMP_CLOSEWINDOW,
  39.  
  40.     WFLG_CLOSEGADGET|WFLG_DRAGBAR|WFLG_SIZEGADGET|
  41.     WFLG_SIMPLE_REFRESH|WFLG_REPORTMOUSE|
  42.     WFLG_ACTIVATE|WFLG_RMBTRAP|WFLG_NOCAREREFRESH,
  43.  
  44.     NULL, NULL, "Pixel Twiddle",
  45.     NULL,
  46.     NULL,
  47.     16, 32, -1, -1,
  48.     CUSTOMSCREEN
  49. };
  50.  
  51. void myexit(void);
  52.  
  53. main(ac, av)
  54. int ac;
  55. char *av[];
  56. {
  57.     short notDone = 1;
  58.     short down = 0;
  59.     char pen = 1;
  60.  
  61.     atexit(myexit);
  62.  
  63.     if (Scr = OpenScreen(&Ns)) {
  64.     Nw.TopEdge= 2;    /*  leave 2 pixel screen title so can drag screen */
  65.     Nw.Height = Scr->Height - Nw.TopEdge;
  66.     Nw.Width  = Scr->Width;
  67.  
  68.     Nw.Screen = Scr;
  69.  
  70.     if (Win = OpenWindow(&Nw)) {
  71.         while (notDone) {
  72.         IntuiMessage *imsg;
  73.  
  74.         WaitPort(Win->UserPort);
  75.         while (imsg = (IntuiMessage *)GetMsg(Win->UserPort)) {
  76.             switch(imsg->Class) {
  77.             case IDCMP_CLOSEWINDOW:
  78.             notDone = 0;
  79.             break;
  80.             case IDCMP_MOUSEBUTTONS:
  81.             switch(imsg->Code) {
  82.             case SELECTDOWN:
  83.                 Move(Win->RPort, imsg->MouseX, imsg->MouseY);
  84.                 down = 1;
  85.                 break;
  86.             case SELECTUP:
  87.                 Draw(Win->RPort, imsg->MouseX, imsg->MouseY);
  88.                 down = 0;
  89.                 break;
  90.             }
  91.             break;
  92.             case IDCMP_MOUSEMOVE:
  93.             if (down)
  94.                 Draw(Win->RPort, imsg->MouseX, imsg->MouseY);
  95.             break;
  96.             }
  97.             ReplyMsg(&imsg->ExecMessage);
  98.             SetAPen(Win->RPort, pen++);
  99.         }
  100.         }
  101.     }
  102.     }
  103.     return(0);
  104. }
  105.  
  106. void
  107. myexit(void)
  108. {
  109.     if (Win) {
  110.     CloseWindow(Win);
  111.     Win = NULL;
  112.     }
  113.     if (Scr) {
  114.     CloseScreen(Scr);
  115.     Scr = NULL;
  116.     }
  117. }
  118.  
  119.